package com.cd.university.controller.typeOfAchievement.achievement;

import com.cd.university.common.RestResult;
import com.cd.university.service.AchievementProcessor;
import com.cd.university.service.impl.AchievementProcessorHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author 陈栋
 * @create 2021/11/3 21:53
 */
@RestController
@RequestMapping("/achievement")
@Api("项目的成果审核")
public class AchievementController {

    @Autowired
    private AchievementProcessorHolder achievementProcessorHolder;

    @GetMapping("/searchAll/{type}")
    @ApiOperation("查询所有的具体成果形式")
    @PreAuthorize("hasAnyAuthority('超级管理员','审核论文成果申请','审核成果获奖申请','审核专利产品申请')")
    public RestResult searchAll(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                @RequestParam(required = false,defaultValue = "6") Integer pageSize,
                                @PathVariable("type") String type) {
        AchievementProcessor processor = achievementProcessorHolder.findApplyAchievementProcessor(type);
        return processor.searchAllAchievement(pageNum, pageSize);
    }

    @GetMapping("/searchAllPass/{type}")
    @ApiOperation("查询所有的已通过的成果形式")
    public RestResult searchAllPass(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                    @RequestParam(required = false,defaultValue = "6") Integer pageSize,
                                    @PathVariable("type") String type) {
        AchievementProcessor processor = achievementProcessorHolder.findApplyAchievementProcessor(type);
        return processor.searchAllPassAchievement(pageNum, pageSize);
    }

    @GetMapping("/searchByName/{type}")
    @ApiOperation("按照成果名称搜索")
    @PreAuthorize("hasAnyAuthority('超级管理员','审核论文成果申请','审核成果获奖申请','审核专利产品申请')")
    public RestResult searchAchByName(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                      @RequestParam(required = false,defaultValue = "6") Integer pageSize,
                                      @RequestParam("achievementName") String achievementName,
                                      @PathVariable("type") String type) {
        AchievementProcessor processor = achievementProcessorHolder.findApplyAchievementProcessor(type);
        return processor.searchAchievementByName(pageNum,pageSize,achievementName);
    }

    @GetMapping("/approved/{type}")
    @ApiOperation("确认成果形式")
    @PreAuthorize("hasAnyAuthority('超级管理员','审核论文成果申请','审核成果获奖申请','审核专利产品申请')")
    public RestResult approvedAchievement(@RequestParam("peId") Integer peId,
                                          @RequestParam("reviewerId") Integer reviewerId,
                                          @PathVariable("type") String type) {
        AchievementProcessor processor = achievementProcessorHolder.findApplyAchievementProcessor(type);
        return processor.approvedAchievement(peId, reviewerId);
    }

    @GetMapping("/seaUserName/{type}")
    @ApiOperation("通过负责人姓名搜索")
    @PreAuthorize("hasAnyAuthority('超级管理员','审核论文成果申请','审核成果获奖申请','审核专利产品申请')")
    public RestResult searchAchByUserName(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                          @RequestParam(required = false,defaultValue = "6") Integer pageSize,
                                          @RequestParam("userName") String userName,
                                          @PathVariable("type") String type) {
        AchievementProcessor processor = achievementProcessorHolder.findApplyAchievementProcessor(type);
        return processor.searchAchievementByUserName(pageNum,pageSize,userName);
    }
}
